package com.ruoyi.waybill.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.waybill.domain.TWayBillExt;
import com.ruoyi.waybill.service.ITWayBillExtService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运单扩展Controller
 * 
 * @author ruoyi
 * @date 2024-05-16
 */
@RestController
@RequestMapping("/waybills/waybillext")
public class TWayBillExtController extends BaseController
{
    @Autowired
    private ITWayBillExtService tWayBillExtService;

    /**
     * 查询运单扩展列表
     */
    @PreAuthorize("@ss.hasPermi('waybills:waybillext:list')")
    @GetMapping("/list")
    public TableDataInfo list(TWayBillExt tWayBillExt)
    {
        startPage();
        List<TWayBillExt> list = tWayBillExtService.selectTWayBillExtList(tWayBillExt);
        return getDataTable(list);
    }

    /**
     * 导出运单扩展列表
     */
    @PreAuthorize("@ss.hasPermi('waybills:waybillext:export')")
    @Log(title = "运单扩展", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TWayBillExt tWayBillExt)
    {
        List<TWayBillExt> list = tWayBillExtService.selectTWayBillExtList(tWayBillExt);
        ExcelUtil<TWayBillExt> util = new ExcelUtil<TWayBillExt>(TWayBillExt.class);
        util.exportExcel(response, list, "运单扩展数据");
    }

    /**
     * 获取运单扩展详细信息
     */
    @PreAuthorize("@ss.hasPermi('waybills:waybillext:query')")
    @GetMapping(value = "/{wayBillId}")
    public AjaxResult getInfo(@PathVariable("wayBillId") Long wayBillId)
    {
        return success(tWayBillExtService.selectTWayBillExtByWayBillId(wayBillId));
    }

    /**
     * 新增运单扩展
     */
    @PreAuthorize("@ss.hasPermi('waybills:waybillext:add')")
    @Log(title = "运单扩展", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TWayBillExt tWayBillExt)
    {
        tWayBillExt.setCreateBy(getNickName());
        return toAjax(tWayBillExtService.insertTWayBillExt(tWayBillExt));
    }

    /**
     * 修改运单扩展
     */
    @PreAuthorize("@ss.hasPermi('waybills:waybillext:edit')")
    @Log(title = "运单扩展", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TWayBillExt tWayBillExt)
    {
        tWayBillExt.setUpdateBy(getNickName());
        return toAjax(tWayBillExtService.updateTWayBillExt(tWayBillExt));
    }

    /**
     * 删除运单扩展
     */
    @PreAuthorize("@ss.hasPermi('waybills:waybillext:remove')")
    @Log(title = "运单扩展", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wayBillIds}")
    public AjaxResult remove(@PathVariable Long[] wayBillIds)
    {
        return toAjax(tWayBillExtService.deleteTWayBillExtByWayBillIds(wayBillIds));
    }
}
